package com.zlq.easydbutils;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.zlq.easydbutils.factory.EasyFactory;

public class UserDaoImpl implements UserDao {

	public User getUserByUsername(String username) throws SQLException {
		return EasyFactory.getRunner().query("select * from users where username = ?", new BeanHandler<User>(User.class),username);
	}
	
	public List getUserByUsername2(String username) throws SQLException {
		return EasyFactory.getRunner().querys("select * from users where username = ?", new BeanListHandler<User>(User.class),username);
	}
	
	
	public User getall(String username) throws SQLException {
		return EasyFactory.getRunner().query("select * from users where username = ?", new BeanHandler<User>(User.class),username);
	}
	

	public void addUser(User user) throws SQLException {
		EasyFactory.getRunner().update("insert into users values(?,?,?)",user.getId(),user.getUsername(),user.getPassword());
	}

}
